package com.lin.cloud.disk.controller;

import com.lin.cloud.disk.common.entity.request.AccountRequestDTO;
import com.lin.cloud.disk.common.utils.Result;
import com.lin.cloud.disk.entity.pojo.Department;
import com.lin.cloud.disk.entity.request.*;
import com.lin.cloud.disk.entity.request.department.*;
import com.lin.cloud.disk.entity.response.PermissionGroupListResponse;
import com.lin.cloud.disk.entity.response.UserInfoResponse;
import com.lin.cloud.disk.manage.IDepartmentManageService;
import com.lin.cloud.disk.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Department)表控制层
 *
 * @author ljc
 * @since 2020-12-10 16:45:59
 */
@RestController
@RequestMapping("/api/department")
@Slf4j
@Api(tags = "部门控制器")
public class DepartmentController {

    @Resource
    private IDepartmentManageService departmentManageService;

    @Resource
    private IDepartmentService departmentService;


    @PostMapping(value = "/getDepartmentPermissionList")
    @ApiOperation(value = "获取部门权限列表")
    public Result<PermissionGroupListResponse> getDepartmentPermissionList(@RequestBody @Validated GetDepartmentPermissionRequest request){
        return Result.success(departmentManageService.getDepartmentPermissionList(request));
    }

    @PostMapping(value = "/createCompanyDepartment")
    @ApiOperation(value = "创建公司部门")
    public Result createCompanyDepartment(@RequestBody @Validated CreateDepartmentRequest request){
        departmentManageService.createCompanyDepartment(request);
        return Result.success();
    }

    @DeleteMapping(value = "/deleteCompanyDepartment")
    @ApiOperation(value = "删除公司部门")
    public Result deleteCompanyDepartment(@RequestBody @Validated DeleteDepartmentRequest request){
        departmentManageService.deleteCompanyDepartment(request);
        return Result.success();
    }

    @PutMapping(value = "/updateCompanyDepartment")
    @ApiOperation(value = "修改公司部门")
    public Result updateCompanyDepartment(@RequestBody @Validated UpdateDepartmentRequest request){
        departmentManageService.updateCompanyDepartment(request);
        return Result.success();
    }

    @PostMapping(value = "/getDepartmentInnerUser")
    @ApiOperation(value = "获取部门内部用户")
    public Result<List<UserInfoResponse>> getDepartmentInnerUser(@RequestBody @Validated GetDepartmentUserRequest request){
        List<UserInfoResponse> departmentUserList = departmentManageService.getDepartmentInnerUser(request);
        return Result.success(departmentUserList);
    }

    @PostMapping(value = "/getUnAllocationDepartmentUser")
    @ApiOperation(value = "获取未分配部门的用户")
    public Result<List<UserInfoResponse>> getUnAllocationDepartmentUser(@RequestBody @Validated AccountRequestDTO accountRequestDTO){
        List<UserInfoResponse> departmentUserList = departmentManageService.getUnAllocationDepartmentUser(accountRequestDTO);
        return Result.success(departmentUserList);
    }


    @PostMapping(value = "/allocationUserToDepartment")
    @ApiOperation(value = "分配/取消分配用户到指定部门")
    public Result allocationUserToDepartment(@RequestBody @Validated  AllocationUserToDepartmentRequest request){
        departmentManageService.allocationUserToDepartment(request);
        return Result.success();
    }

    @PostMapping(value = "/findDepartmentById")
    @ApiOperation(value = "通过ID获取部门详情")
    public Result<Department> findDepartmentById(@RequestBody @Validated  findDepartmentByIdRequest request){
        Department department = departmentService.findDepartmentById(request);
        return Result.success(department);
    }




}